<?php

namespace app\common\logic;

/**
 * 产品案例逻辑
 */
class Product extends LogicBase
{

    /**
     * 获取产品案例列表
     */
    public function getProductList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelProduct->alias('a');
        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelProduct->getList($where, $field, $order, DB_LIST_ROWS);
    }
    
    
     /**
     * 获取项目列表
     */
    public function getProductList2($param,$where = [], $field = 'a.*', $order = '')
    {

        $field = 'id,pro_name,pro_img,pro_descrit,updated_at,pro_url,status,category_id'; 
        
        $category = array_key_exists('category_id',$param)?$param['category_id']:'';
      
        switch ($category){
            
            case 1:
                
                $where['category_id'] = 1;
                break;
            case 2:
                
                $where['category_id'] = 2;
                break;
            case 3:
                
                $where['category_id'] = 3;
                break;
            case 4:
                
                $where['category_id'] = 4;
                break;
            default :
                
                $where['category_id'] = array('in','1,2,3,4');
        }
 
        $where['status'] = 1; 
        
        return $this->modelProduct->getList($where, $field, $order, 15);
    }
    
    
    /**
     * 获取首页项目列表
     */
    public function getProductList3($param,$where = [], $field = 'a.*', $order = '')
    {

        $field = 'id,pro_name,pro_img,pro_descrit,updated_at,pro_url,status,category_id'; 
        
        $category = array_key_exists('category_id',$param)?$param['category_id']:'';
      
        switch ($category){
            
            case 1:
                
                $where['category_id'] = 1;
                break;
            case 2:
                
                $where['category_id'] = 2;
                break;
            case 3:
                
                $where['category_id'] = 3;
                break;
            case 4:
                
                $where['category_id'] = 4;
                break;
            default :
                
                $where['category_id'] = array('in','1,2,3,4');
        }
 
        $where['status'] = 1; 
        
        return $this->modelProduct->getList($where, $field, $order, 8,[],'',8);
    }
    
    
    /**
     * 获取产品案例列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.pro_name|a.pro_descrit'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
     /**
     * 产品案例信息编辑
     */
    public function productEdit($data = [],$type=1,$url="campanyWeb")
    {
        $data['category_id'] = $type;

        $validate_result = $this->validateProduct->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateProduct->getError()];
        }
        
        $url = url($url);   
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';

        if($handle_text == '新增'){
            
            $data['created_at'] = time();
        }
        
        $data['updated_at'] = time();

        $result = $this->modelProduct->setInfo($data);

        $result && action_log($handle_text, '产品案例' . $handle_text . '，name：' . $data['pro_name']);
        
        return $result ? [RESULT_SUCCESS, '产品案例操作成功', $url] : [RESULT_ERROR, $this->modelProduct->getError()];
    }
  
     /**
     * 获取产品案例信息
     */
    public function getProductInfo($where = [], $field = 'a.*')
    {
        $this->modelProduct->alias('a');
       
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelProduct->getInfo($where, $field);
    }
    
    /**
     * 获取产品案例分类列表
     */
    public function getProductCategoryList($where = [], $field = true, $order = '', $paginate = 0)
    {
        return $this->modelProduct->getList($where, $field, $order, $paginate);
    }
}

